'use strict';

/**
 * 消息通知Controller
 */
app.controller('HeaderCtrl', 
	['$scope', 'dialogs', 'HeaderService','$state','$uibModal',
	function($scope, dialogs, HeaderService,$state,$uibModal) {
	var vm = $scope.vm = this;
	//refresh();
	function refresh(){
		HeaderService.getLastestInfo().then(function(data){
			vm.infoCount = data.length;
			//至多展示最新前两条消息
			vm.infoList = data.splice(0,2);
		});
	}
	vm.messageClick = function(id){
		var param;
		for(var i=0;i<vm.infoList.length;i++){
			if(vm.infoList[i].infoId == id){
				param = angular.copy(vm.infoList[i]);
			}
		}
		var modalInstance = $uibModal.open({
   	     animation: true,
   	     templateUrl: ISS.getPath('app/modules/basic/infocenter/modals/infoDetail.html'),
   	     controller: 'InfoDetailCtrl',
   	     backdrop:'static',
   	     resolve: {
   	    	 param: function () {
   	         return param;
   	       }
   	     }
   	   });
		modalInstance.result.then(function (result) {
			refresh();
	    	$scope.$emit("RefreshGrid", { description: "刷新消息中心表格" });
	    		
		});
	}
	$scope.$on("ReadMessageHeader", function (event, data) {
		refresh();
    });
	
}]);
